﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaxLeaf.Common;
using MaxLeaf.DB;
using System.Data;
using MySql.Data.MySqlClient;

namespace MaxLeaf.DAL.K2W
{
   /// <summary>
   /// 职员
   /// </summary>
    public class t_Base_EmpDAL : BaseDAL
    {
        /*
        Insert into k3_base_emp (Employee_id,db_id,department_id,Staff_name,mobile_phone,modify_time) 
         * values(Employee_id,db_id,department_id,Staff_name,mobile_phone,modify_time)
        */
        public t_Base_EmpDAL()
            : base()
        {
            strTableName = "k3_base_emp";
            strOrgTableName = "t_Base_Emp";

            strKeyFieldName = "Fitemid";
            strOrgKeyFieldName = "FItemID";

            strFieldNames = "db_id,department_id,Staff_name,mobile_phone,is_delete";
            strOrgFieldNames = "0,1,2,3";
        }
        protected override void DAL_GetFieldData(DBAccess dbOrgK3Con, DBAccess dbDestWebReadCon, DBAccess dbDestWebWriteCon, string strFieldName, string strOrgFieldName, DataRow drOrgData, DataRow drDestData)
        {
            if (strFieldName.Equals("Db_id", StringComparison.InvariantCultureIgnoreCase))
            {
                KeyValuePair<string, IDataParameter[]> kvp = dbDestWebReadCon.CreateCondParam(new Dictionary<string, object>() { { "dbname", dbOrgK3Con.ServerDBName } });
                string strSql = string.Format("select db_id from k3_db_main Where {0}", kvp.Key);
                drDestData[strFieldName] = dbDestWebReadCon.GetValue(strSql, kvp.Value);
            }
            else if (strFieldName.Equals("department_id", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = drOrgData["FDepartmentID"];

                new t_departmentDAL().Update(dbOrgK3Con, dbDestWebReadCon, dbDestWebWriteCon, CvtFunc.ToString(drOrgData["FDepartmentID"]));
            }
            else if (strFieldName.Equals("Staff_name", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = drOrgData["FName"];
            }
            else if (strFieldName.Equals("mobile_phone", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = drOrgData["FPhone"];
            }
            else if (strFieldName.Equals("is_delete", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = CvtFunc.ToBoolean(drOrgData["Fdeleted"]);
            }
        }
        
          
    }
}